package main

import (
	"fmt"
	"math/rand"
	"sync"
	"time"
)

var missionCompleted bool

func main() {
	var wg sync.WaitGroup
	var once sync.Once
	wg.Add(100)
	for i := 0; i < 100; i++ {
		go func() {
			if foundTreasure() {
				once.Do(markMissionCompleted)
			}
			wg.Done()
		}()
	}

	wg.Wait()
	checkMissionCompleted()

}

func checkMissionCompleted() {
	if missionCompleted {
		fmt.Println("missionCompleted")
	} else {
		fmt.Println("misssion not done")
	}
}

func markMissionCompleted() {
	fmt.Println("mark misssion completed")
	missionCompleted = true
}

func foundTreasure() bool {
	rand.Seed(time.Now().UnixNano())
	return 0 == rand.Intn(10)
}
